# -*- coding: utf-8 -*-
'''
    :file: views.py
    :author: -Farmer
    :url: https://blog.farmer233.top
    :date: 2021/02/09 01:14:04
'''

from flask import jsonify, request, g

from app import app, db, auth
from app.models import User


@app.route("/regUser")
def regUser():
    req_data = request.json
    reg_user = User()
    reg_user.username = req_data.get("username")
    reg_user.set_password(req_data.get("password"))
    db.session.add(reg_user)
    db.session.commit()
    return "reg success."


@app.route('/login')
@auth.login_required
def login():
    return jsonify({ 'data': 'Hello, %s!' % g.user.username })
    # req_data = request.json
    # if req_data.get('username') == None or req_data.get('password') == None:
    #     return "Null"

@app.route("/loginRes")
def res():
    return "You was login."